package com.hzlx.types.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.types.domain.DefectTypes;
import com.hzlx.types.service.IDefectTypesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 缺陷类型标准库（用于质量检验中的缺陷分类）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quality")
public class DefectTypesController extends BaseController
{
    @Autowired
    private IDefectTypesService defectTypesService;

    /**
     * 查询缺陷类型标准库（用于质量检验中的缺陷分类）列表
     */
    @RequiresPermissions("quality-service:types:list")
    @GetMapping("/types/list")
    public TableDataInfo list(DefectTypes defectTypes)
    {
        startPage();
        List<DefectTypes> list = defectTypesService.selectDefectTypesList(defectTypes);
        return getDataTable(list);
    }

    /**
     * 导出缺陷类型标准库（用于质量检验中的缺陷分类）列表
     */
    @RequiresPermissions("quality-service:types:export")
    @Log(title = "缺陷类型标准库（用于质量检验中的缺陷分类）", businessType = BusinessType.EXPORT)
    @PostMapping("/types/export")
    public void export(HttpServletResponse response, DefectTypes defectTypes)
    {
        List<DefectTypes> list = defectTypesService.selectDefectTypesList(defectTypes);
        ExcelUtil<DefectTypes> util = new ExcelUtil<DefectTypes>(DefectTypes.class);
        util.exportExcel(response, list, "缺陷类型标准库（用于质量检验中的缺陷分类）数据");
    }

    /**
     * 获取缺陷类型标准库（用于质量检验中的缺陷分类）详细信息
     */
    @RequiresPermissions("quality-service:types:query")
    @GetMapping(value = "/types/{defectTypeId}")
    public AjaxResult getInfo(@PathVariable("defectTypeId") String defectTypeId)
    {
        return success(defectTypesService.selectDefectTypesByDefectTypeId(defectTypeId));
    }

    /**
     * 新增缺陷类型标准库（用于质量检验中的缺陷分类）
     */
    @RequiresPermissions("quality-service:types:add")
    @Log(title = "缺陷类型标准库（用于质量检验中的缺陷分类）", businessType = BusinessType.INSERT)
    @PostMapping("/types")
    public AjaxResult add(@RequestBody DefectTypes defectTypes)
    {
        return toAjax(defectTypesService.insertDefectTypes(defectTypes));
    }

    /**
     * 修改缺陷类型标准库（用于质量检验中的缺陷分类）
     */
    @RequiresPermissions("quality-service:types:edit")
    @Log(title = "缺陷类型标准库（用于质量检验中的缺陷分类）", businessType = BusinessType.UPDATE)
    @PutMapping("/types")
    public AjaxResult edit(@RequestBody DefectTypes defectTypes)
    {
        return toAjax(defectTypesService.updateDefectTypes(defectTypes));
    }

    /**
     * 删除缺陷类型标准库（用于质量检验中的缺陷分类）
     */
    @RequiresPermissions("quality-service:types:remove")
    @Log(title = "缺陷类型标准库（用于质量检验中的缺陷分类）", businessType = BusinessType.DELETE)
	@DeleteMapping("/types/{defectTypeIds}")
    public AjaxResult remove(@PathVariable String[] defectTypeIds)
    {
        return toAjax(defectTypesService.deleteDefectTypesByDefectTypeIds(defectTypeIds));
    }
}
